class: center, middle, inverse, title-slide # World Renewable Energy Consumption ## For Europe, the UK, the US, Canada, and China ### Loren, Owen, and Jackie ### Bates College ### 2022-04-07 --- ```r cleandata <- alldata %>% filter(country %in% c("United States", "Canada", "United Kingdom", "Spain", "France", "Germany", "Switzerland", "Italy", "Norway", "Sweden", "Finland", "China", "Brazil", "India", "Russia", "Japan", "New Zealand", "Australia", "Africa", "South Africa"), year >= 1990) %>% select(country, year, wind_energy_per_capita, wind_consumption, wind_share_energy, wind_cons_change_twh, gdp, solar_energy_per_capita, solar_consumption, solar_share_energy, solar_cons_change_twh, renewables_energy_per_capita, renewables_consumption, renewables_cons_change_twh, renewables_share_energy, population, nuclear_consumption, nuclear_share_energy, nuclear_cons_change_twh, nuclear_energy_per_capita, hydro_share_energy, hydro_cons_change_twh, hydro_energy_per_capita, hydro_consumption, fossil_cons_change_twh, fossil_fuel_consumption, fossil_energy_per_capita, fossil_share_energy, energy_cons_change_twh, energy_per_gdp, energy_per_capita, biofuel_cons_change_twh, biofuel_share_energy, biofuel_cons_per_capita, biofuel_consumption) #use this data for line plots etc (more consolidated country list) ``` ```r style_xaringan( title_slide_background_image = "img/confetti.jpg" ) ``` class: center, middle, testing ## A statement of the overall goal / research question --- class: inverse, center, middle # Section title --- # Hello World - Click the `Knit` button to compile your presentation - Make sure to commit and push all resulting files to your GitHub repo --- class: inverse, middle, center # Using xaringan --- # xaringan - The presentation is created using the `xaringan` package - Use `---` to separate slides and `--` for incremental builds -- - Like this --- # Layouts You can use plain text - or bullet points .pull-left[ or text in two columns `\(^*\)` ] .pull-right[ - like - this ] .footnote[ [*] And add footnotes ] --- # Code ```r leaflettdata <- alldata %>% filter(year >= 1990) %>% select(country, year, wind_energy_per_capita, wind_consumption, wind_share_energy, wind_cons_change_twh, gdp, solar_energy_per_capita, solar_consumption, solar_share_energy, solar_cons_change_twh, renewables_energy_per_capita, renewables_consumption, renewables_cons_change_twh, renewables_share_energy, population, nuclear_consumption, nuclear_share_energy, nuclear_cons_change_twh, nuclear_energy_per_capita, hydro_share_energy, hydro_cons_change_twh, hydro_energy_per_capita, hydro_consumption, fossil_cons_change_twh, fossil_fuel_consumption, fossil_energy_per_capita, fossil_share_energy, energy_cons_change_twh, energy_per_gdp, energy_per_capita, biofuel_cons_change_twh, biofuel_share_energy, biofuel_cons_per_capita, biofuel_consumption) #use this data for leaflets - uses all countries ``` ```r testleaflet <- leaflettdata %>% filter(year == "2018") ``` ```r testleaflet <- testleaflet %>% left_join(world_spdf2, by = c("country" = "NAME")) %>% st_as_sf() ``` ```r #2018 leaflet pal2 <- colorNumeric(palette = "RdYlGn", domain = testleaflet$renewables_share_energy) labels <- sprintf("<strong>%s</strong><br/>%s ", testleaflet$country, testleaflet$renewables_share_energy) %>% lapply(htmltools::HTML) m <- leaflet(data = testleaflet) %>% addTiles() %>% setView( lat=10, lng=0 , zoom=1) %>% addPolygons(fillColor = ~pal2(testleaflet$renewables_share_energy), fillOpacity = 1, color = "white", opacity = 0.7, weight = 1, label = labels) %>% addLegend("bottomright", pal = pal2, values = ~testleaflet$renewables_share_energy, title = "2018 Renewable<br> Energy Share", opacity = 1) m ```
```r ninetyleaflet <- leaflettdata %>% filter(year == "1990") ``` ```r ninetyleaflet <- ninetyleaflet %>% left_join(world_spdf2, by = c("country" = "NAME")) %>% st_as_sf() ``` ```r #attempt at making leaflet where you can switch between years (uses two data frames) pal3 <- colorNumeric(palette = "RdYlGn", domain = ninetyleaflet$renewables_share_energy) pal2 <- colorNumeric(palette = "RdYlGn", domain = testleaflet$renewables_share_energy) #labels <- sprintf("<strong>%s</strong><br/>%s ", ninetyleaflet$country, #ninetyleaflet$renewables_share_energy) %>% # lapply(htmltools::HTML) b <- leaflet(data = ninetyleaflet) %>% addTiles() %>% setView( lat=10, lng=0 , zoom=2) %>% addPolygons(fillColor = ~pal3(ninetyleaflet$renewables_share_energy), fillOpacity = 1, color = "white", opacity = 0.7, weight = 1, #label = labels, group = "1990") %>% addPolygons(fillColor = ~pal2(testleaflet$renewables_share_energy), fillOpacity = 1, color = "white", opacity = 0.7, weight = 1, #label = labels, group = "2018") %>% addLayersControl( baseGroups = c("2018", "1990"), options = layersControlOptions(collapsed = FALSE)) #addLegend("bottomright", pal = pal3, values = ~ninetyleaflet$renewables_share_energy, #title = "1990 Renewable<br> Energy Share", #opacity = 1) b ```
```r multiyeardata <- leaflettdata %>% filter(year %in% c("1990", "2018")) %>% mutate(eightteendata = case_when(year == "2018" ~ renewables_share_energy), ninetydata = case_when(year == "1990" ~ renewables_share_energy) ) multiyeardata <- multiyeardata %>% left_join(world_spdf2, by = c("country" = "NAME")) %>% st_as_sf() ``` ```r #attempt at making leaflet where you can switch between years using one data frame pal3 <- colorNumeric(palette = "RdYlGn", domain = multiyeardata$ninetydata) pal2 <- colorNumeric(palette = "RdYlGn", domain = multiyeardata$eightteendata) #labels <- sprintf("<strong>%s</strong><br/>%s ", ninetyleaflet$country, #ninetyleaflet$renewables_share_energy) %>% # lapply(htmltools::HTML) map1 <- leaflet(data = multiyeardata) %>% addPolygons(fillColor = ~pal2(multiyeardata$eightteendata), fillOpacity = 1, color = "white", opacity = 0.7, weight = 1, #label = labels, group = "2018") %>% addPolygons(fillColor = ~pal3(multiyeardata$ninetydata), fillOpacity = 1, color = "white", opacity = 0.7, weight = 1, #label = labels, group = "1990") %>% setView( lat=10, lng=0 , zoom=2) %>% addLayersControl( baseGroups = c("2018", "1990"), options = layersControlOptions(collapsed = FALSE)) #addLegend("bottomright", pal = pal3, values = ~ninetyleaflet$renewables_share_energy, #title = "1990 Renewable<br> Energy Share", #opacity = 1) map1 ```
--- # Plots ```r #cleaning data to make bar charts barchartdata <- alldata %>% filter(country %in% c("United States", "Canada", "United Kingdom", "Spain", "France", "Germany", "Switzerland", "Italy", "Norway", "Sweden", "Finland", "China", "Brazil", "India", "Russia", "Japan", "New Zealand", "Australia", "Africa", "South Africa"), year >= 1990) %>% select(country, year, wind_consumption, solar_consumption, nuclear_consumption, hydro_consumption, biofuel_consumption, coal_consumption, gas_consumption, oil_consumption) barchartdata <- transform(barchartdata, overall_consumption = (wind_consumption+ solar_consumption + nuclear_consumption + hydro_consumption + biofuel_consumption + coal_consumption + gas_consumption + oil_consumption)) barcharttransform <- gather(barchartdata, key = "energy_type", value = "consumption", -country, -year, -overall_consumption) barcharttransform <- barcharttransform[order(-barcharttransform$overall_consumption),] barcharttransform$country <- factor(barcharttransform$country, levels = unique(barcharttransform$country)) colnames(barcharttransform) ``` ``` ## [1] "country" "year" "overall_consumption" ## [4] "energy_type" "consumption" ``` ```r barcharttransform %>% filter(year >= 2000) %>% ggplot(aes(x = year, y = overall_consumption, fill = energy_type)) + geom_bar(position="stack", stat="identity") + facet_wrap(vars(country)) + labs(title = "Energy consumption by country", subtitle = "2000-2020", x = "Year", y = "Primary Energy Consumption (TWh)", fill = "Energy Type") + theme_minimal() + scale_fill_brewer(palette = "RdYlGn") ``` ``` ## Warning: Removed 152 rows containing missing values (position_stack). ``` <img src="presentation_files/figure-html/barchart-transformed-fig-1.png" width="80%" /> ```r barchartchinausa <- barcharttransform %>% filter(country %in% c("United States", "China"), year >= 2000) fig <- ggplot( data = barchartchinausa, aes(x = year, y = overall_consumption, fill = energy_type)) + geom_area() + facet_wrap(vars(country)) + labs(title = "Energy consumption by for China and the USA", subtitle = "2000-2020", x = "Year", y = "Primary Energy Consumption (TWh)", fill = "Energy Type") + theme_minimal() + scale_fill_brewer(palette = "RdYlGn") ggplotly(fig) ``` ``` ## Warning: Removed 16 rows containing missing values (position_stack). ```
```r leaflettdata <- leaflettdata %>% left_join(world_spdf2, by = c("country" = "NAME")) %>% st_as_sf() ``` <img src="presentation_files/figure-html/plot-iris-1.png" width="80%" /> --- ## Plot and text .pull-left[ - Some text - goes here ] .pull-right[ ] --- # Tables If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g., <table> <thead> <tr> <th style="text-align:right;"> Sepal.Length </th> <th style="text-align:right;"> Sepal.Width </th> <th style="text-align:right;"> Petal.Length </th> <th style="text-align:right;"> Petal.Width </th> <th style="text-align:left;"> Species </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 5.1 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.9 </td> <td style="text-align:right;"> 3.0 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.7 </td> <td style="text-align:right;"> 3.2 </td> <td style="text-align:right;"> 1.3 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.6 </td> <td style="text-align:right;"> 3.1 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> 3.6 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.4 </td> <td style="text-align:right;"> 3.9 </td> <td style="text-align:right;"> 1.7 </td> <td style="text-align:right;"> 0.4 </td> <td style="text-align:left;"> setosa </td> </tr> </tbody> </table> --- # Images <div class="figure" style="text-align: center"> <img src="https://images.unsplash.com/photo-1535448033526-c0e85c9e6968?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80" alt="Image credit: Photo by Jörg Angeli on Unsplash." width="60%" /> <p class="caption">Image credit: Photo by Jörg Angeli on Unsplash.</p> </div> Or you can also include a full page image. See next slide. --- background-image: url(https://images.unsplash.com/photo-1535448033526-c0e85c9e6968?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80) --- # Math Expressions You can write LaTeX math expressions inside a pair of dollar signs, e.g. $\alpha+\beta$ renders `\(\alpha+\beta\)`. You can use the display style with double dollar signs: ``` $$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$ ``` `$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$` Limitations: 1. The source code of a LaTeX math expression must be in one line, unless it is inside a pair of double dollar signs, in which case the starting `$$` must appear in the very beginning of a line, followed immediately by a non-space character, and the ending `$$` must be at the end of a line, led by a non-space character; 1. There should not be spaces after the opening `$` or before the closing `$`. 1. Math does not work on the title slide (see [#61](https://github.com/yihui/xaringan/issues/61) for a workaround). --- # Feeling adventurous? - Want to find out more about `xaringan`? See https://slides.yihui.name/xaringan/#1. - You are welcomed to use the default styling of the slides. In fact, that's what I expect majority of you will do. You will differentiate yourself with the content of your presentation. - But some of you might want to play around with slide styling. The `xaringanthemer` provides some solutions for this that: https://pkg.garrickadenbuie.com/xaringanthemer. - And if you want more bells and whistles, there is also `xaringanExtra`: https://pkg.garrickadenbuie.com/xaringanExtra.